//
// Created by Administrator on 2024/6/3.
// 合并两个有序链表
//

#include <iostream>
#include "linkedListUtil.h"
using namespace std;

Node * merge(Node *h,Node *hh)
{
    Node *head=new Node{-1,nullptr};
    h=h->next;
    hh=hh->next;
    Node *cur = head;
    while(h && hh)
    {
        if (h->v<=hh->v)
        {
            cur->next=new Node{h->v, nullptr};
            h=h->next;
        } else{
            cur->next=new Node{hh->v, nullptr};
            hh=hh->next;
        }
        cur=cur->next;
    }
    while(h)
    {
        cur->next=new Node{h->v, nullptr};
        h=h->next;
    }
    while(hh)
    {
        cur->next = new Node{hh->v, nullptr};
        hh = hh->next;
    }
    return head;
}
int main()
{
    vector<int> v1{1,3,5,7,9};
    vector<int> v2{0,2,4,6,8};
//    vector<int> v1{1};
//    vector<int> v2{};
    Node *h1=build(v1);
    Node *h2=build(v2);
    Node *newHead=merge(h1,h2);
    printLinkedList(newHead);
    return 0;
}